#include <REGX52.H>
#include "matrix.h"
#include "LCD1602.H"

void main()
{
	char Key_num = 0;
	
	int password = 0;
	int count = 0;
	
	LCD_Init();
	
	LCD_ShowString(1,1,"input password");
	
	LCD_ShowNum(2,1,Key_num,4);
	
	while(1)
	{	
		
		Key_num = Matrix_num();
		
		if(Key_num)
		{
			if(Key_num < 11)
				{
					if(count < 4)//限定输入为四位数
						{
							password *= 10; //向左移一位
					
							password += Key_num % 10; //取0~9
			
							LCD_ShowNum(2,1,password,4);
				
							count++;
						}
				}
			
				if(Key_num == 11 && password == 1234) //密码为1234
					{
						LCD_ShowString(2,14,"OK ");
				
						password = 0;
						count = 0;
						
						LCD_ShowNum(2,1,password,4);
					}				
				else if(Key_num == 11 && password != 1234)
					{
						LCD_ShowString(2,14,"ERR");
					
						password = 0;
						count = 0;
					
						LCD_ShowNum(2,1,password,4);
					}
				
				
				if(Key_num == 12) //重新输入
					{
						password = 0;
						count = 0;
					
						LCD_ShowNum(2,1,password,4);
					}	
			
		}
			
		
	}
}


